<template>
  <van-row>
    <van-nav-bar title="调用GPRS" left-text="返回" left-arrow @click-left="onClickLeft">
    </van-nav-bar>
    <van-row class="side-nav">
      <h1 class="vant-title">
        <img src="https://img.yzcdn.cn/vant/logo.png">
        <span>获得GPRS位置</span>
      </h1>
      <van-row>
        <h5>位置</h5>
        <van-cell-group>
          <van-cell title="纬度"  >{{latitude}}</van-cell>
          <van-cell title="经度"  >{{longitude}}</van-cell>
          <van-cell title="海拔"  >{{altitude}}</van-cell>
          <van-cell title="水平精度" >{{accuracy}}</van-cell>
          <van-cell title="垂直精度"  >{{altitudeAccuracy}}</van-cell>
          <van-cell title="方向" >{{heading}}</van-cell>
          <van-cell title="速度" >{{speed}}</van-cell>
          <van-cell title="纬度"  >{{speed}}</van-cell>
        </van-cell-group>
        <van-button type="default" class="getPhoto" @click="takePicture">获取</van-button>
      </van-row>
    </van-row>
  </van-row>
</template>

<script>
import { Toast } from 'vant'

export default {
  name: 'Gprs',
  data () {
    return {
      latitude: '1',
      longitude: '2',
      altitude: '3',
      accuracy: '4',
      altitudeAccuracy: '5',
      heading: '6',
      speed: '7',
      timestamp: '8'
    }
  },
  methods: {
    takePicture () {
      this.getPosition()
    },
    getPosition () {
      var watchID = navigator.geolocation.getCurrentPosition(this.getPositionSuccess, this.getPositionError,
        {enableHighAccuracy: false, timeout: 15000, maximumAge: 10000, min: 1})
      navigator.geolocation.clearWatch(watchID)
    },
    // 1-1 查询当前位置信息成功
    getPositionSuccess (position) {
      this.latitude = String(position.coords.latitude)
      this.longitude = String(position.coords.longitude)
    },
    // 1-2 查询当前位置信息失败
    getPositionError (err) {
      var msg = 'code: ' + err.code + '\n' +
        'message: ' + err.message + '\n'
      Toast('s失败' + msg)
    },
    onClickLeft () {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
  .van-doc-demo-block__title{
    margin: 0;
    font-weight: 400;
    font-size: 14px;
    color: rgba(69,90,100,.6);
    text-align: left;
  }
  .side-nav{
    box-sizing: border-box;
    width: 100%;
    padding: 64px 10px 10px;
  }
  .side-nav .vant-desc{
    margin: 0 0 40px;
    color: #7d7e80;
    font-size: 14px;
    text-align: left;
  }
  .vant-title{
    font-weight: normal;
    -webkit-user-select: none;
    user-select: none;
    margin: 0 0 16px;
    text-align: left;
  }
  .side-nav .vant-title img {
    width: 36px;
  }
  .van-cell__title{
    text-align: left;
  }
  .comment{
    margin: 10px 0px;
  }
  .getPhoto{
    width: 100%;
  }
  #myImage{
    width: 100%;
  }
</style>
